{% set pypi_name = 'virtualbmc' %}
{% set upstream_version = upstream_version('2.2.0') %}
{% set rpm_release = '1' %}
{% set source = url_pypi() %}

Name:           {{ py2name(py_versions='py3') }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        Python module to create virtual BMCs for controlling virtual instances via IPMI
License:        {{ license('Apache-2.0') }}
Group:          Development/Languages/Python
URL:            https://docs.openstack.org/{{ pypi_name }}
Source0:        {{ source }}
Source1:        virtualbmc.service
BuildRequires:  fdupes
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('pbr') }}
Requires:       {{ py3('cliff') }}
Requires:       {{ py3('libvirt-python') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('pyghmi') }}
Requires:       {{ py3('pyzmq') }}
Requires:       {{ py3('six') }}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(postun): systemd
Requires(preun): systemd
%endif
%if 0%{?suse_version}
Requires(post): update-alternatives
Requires(postun): update-alternatives
%else
# on RDO, update-alternatives is in chkconfig
Requires(post): chkconfig
Requires(postun): chkconfig
%endif

%description
A virtual BMC for controlling virtual machines using IPMI commands.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

%build
%py3_build

%install
%py3_install

# directories
install -d -m 755 %{buildroot}%{_datadir}/{{ pypi_name }}
install -d -m 755 %{buildroot}%{_sharedstatedir}/{{ pypi_name }}
install -d -m 750 %{buildroot}%{_localstatedir}/lib/{{ pypi_name }}

# systemd
install -p -D -m 444 %{SOURCE1} %{buildroot}%{_unitdir}/virtualbmc.service

%post
%systemd_post virtualbmc.service

%postun
%systemd_postun virtualbmc.service

%preun
%systemd_preun virtualbmc.service

%files
%license LICENSE
%{python3_sitelib}/*
%{_bindir}/vbmc
%{_bindir}/vbmcd
%{_unitdir}/virtualbmc.service

%changelog
